﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GLImp;

namespace CastleOfTheDisillusioned {
	class MainCamera {
		public static Camera2D CameraMain;

		public static void Init() {
			MainCamera.CameraMain = new Camera2D();
			MainCamera.CameraMain.OnRender += Render2D;

			CameraMain.CenterOnTarget(false);
		}

		static void Render2D() {
			GameState.CurrentState.Draw();
			ParticleManager.Draw();
		}

		public static void CenterView(double X, double Y) {
			CameraMain.CenterOnTarget(false);
			CameraMain.SetLocation(X - (CameraMain.Width / 2), Y - (CameraMain.Height / 2));
		}

		public static void CenterView(double X, double Y, double Left, double Top, double Right, double Bottom) {
			CameraMain.CenterOnTarget(false);
			CameraMain.SetLocation(X - (CameraMain.Width / 2), Y - (CameraMain.Height / 2));

			CameraMain.Y = Math.Max(CameraMain.Y, Top);
			if (CameraMain.Bottom > Bottom) {
				CameraMain.Y = Bottom - CameraMain.Height;
			}

			if (CameraMain.Right > Right) {
				CameraMain.X = Right - CameraMain.Width;
			}
			CameraMain.X = Math.Max(CameraMain.X, Left);
		}
	}
}
